﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using G.Model;

namespace G.Runtime
{
    public class GameImages : KeyedCollection<GameLocation, GameImage>
    {
        public delegate void ImageHandler(GameLocation location);
        public event ImageHandler Changed;
        
        private GameSpace _GameSpace;
        
        public GameImages(GameSpace pGameSpace)
        {
            _GameSpace = pGameSpace;
        }
        
        protected override GameLocation GetKeyForItem(GameImage item)
        {
            return item.GameLocation;
        }
        
        protected override void InsertItem(int index, GameImage item)
        {
            base.InsertItem(index, item);
            FireChanged(item.GameLocation);
        }
        
        protected override void RemoveItem(int index)
        {
            GameImage item = base[index];
            base.RemoveItem(index);
            FireChanged(item.GameLocation);
        } 
        
        protected override void SetItem(int index, GameImage item)
        {
            base.SetItem(index, item);
            FireChanged(item.GameLocation);
        } 
        
        private void FireChanged(GameLocation loc)
        {
            if (Changed != null)
            {
                Changed(loc);
            }
        }
        
    }
}
